package com.example.zerocopy.mmap;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

public class Test {


	public static final String source = "F:\\copy\\2.txt";
	public static final String dest = "F:\\copy\\1.txt";


	public static void main(String[] args) throws IOException {
		FileChannel sourceChannel = new RandomAccessFile(dest,"rw").getChannel();
		FileChannel destChannel = new RandomAccessFile(source,"rw").getChannel();
		long start = System.currentTimeMillis();
		MappedByteBuffer map = destChannel.map(FileChannel.MapMode.READ_WRITE,0,sourceChannel.size());
		sourceChannel.write(map);
		map.flip();
		long end = System.currentTimeMillis();
        System.out.println("耗时"+(end-start));
  }
}
